package bairui.international.console.web.controller.advance.category;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.lianjing.sh.validate.spring.exception.ValidateObjectException;

import bairui.international.common.config.Config_Setup;
import bairui.international.model.domain.jpa.TB_ProductCategory;
import bairui.international.service.Service_ProductCategory;

/**
 *
 * 编辑
 *
 * @generated
 * 
 * @see STest_C_Advance_Category_Edit_Edit 测试
 *
 */
@Controller
public class C_Advance_Category_Edit_Edit
 extends SC_Advance_Category_Edit_Edit 
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
	
	/**
	 * 编辑
	 */
	@Action(Edit.class)
	@PutMapping(Edit.RequestMappingValue)
	public @FomatOutput @ResponseBody Object edit(
		@Valid Edit.InputModel input, 
		@PathVariable(name=Edit.PathVariableName.Id) long id
	) throws Exception {
		TB_ProductCategory bean = service_ProductCategory.findById(id);
		if(null == bean.getParent() && !input.getName().trim().equals(Config_Setup.Advance)){
			throw new ValidateObjectException("object", "", "业务需要名称不能修改");
		}
		service_ProductCategory.update(id, input);
		//
		return null;
	}
	

}
